﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using ITM495.Lab2.Core;
using ITM495.Lab2.Core.Entities;

namespace ITM495.Lab2.Impl.Readers
{
    public class BinaryReader: IReader<Tweet>
    {
        protected String Path { get; set; }

        public BinaryReader(string path)
        {
            Path = path;
        }

        #region IReader<Tweet> Members

        public IList<Tweet> Read()
        {
            var serializer = new BinaryFormatter();

            using (var binaryStream = new FileStream(Path, FileMode.Open))
            {
                return serializer.Deserialize(binaryStream) as IList<Tweet>;
            }
        }

        #endregion
    }
}
